package cn.keniykey.mc.viewlibrary.view.api.template;

import java.util.List;

import javax.annotation.Nullable;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import cn.keniykey.mc.viewlibrary.container.api.EContainerType;
import cn.keniykey.mc.viewlibrary.view.api.AbFrameView;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewBundle;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewIntent;

public final class ChooseViewIntentBuilder {
	private FrameViewIntent intent;
	private FrameViewBundle bundle;
	
	static enum EChooseMenuViewIntentKey{
		CUSTOMDISPLAY,CUSTOMDISPLAY_CONFIRM,CUSTOMDISPLAY_VETO,CUSTOMDISPLAY_CANCEL,CUSTOMDISPLAY_COUNTDOWN,CUSTOMDISPLAY_PROMPT,
		CUSTOMGRID,CUSTOMGRID_MENUTYPE,CUSTOMGRID_CONFIRM,CUSTOMGRID_VETO,CUSTOMGRID_CANCEL,CUSTOMGRID_COUNTDOWN,CUSTOMGRID_PROMPT,
		CUSTOM_TITLE,COUNTDOWN,
		CUSTOM_PROMPT_NAME,CUSTOM_PROMPT_LORE,
		FORWARD_CONTENT;
	}
	
	public ChooseViewIntentBuilder(Class<? extends AbFrameView> clazz_targetview1) {
		this.intent = new FrameViewIntent(clazz_targetview1);
	}
	
	public FrameViewIntent build() {
		if(this.intent == null) throw new RuntimeException("Already built and returned Intent, recreate it(已经构建过并返回Intent，请重新创建)");
		try {
			return this.intent;
		}finally {
			this.intent = null;
			this.bundle = null;
		}
	}
	private void putValue(EChooseMenuViewIntentKey key,@Nullable Object value) {
		if(null == this.bundle) this.intent.putExtras((this.bundle = new FrameViewBundle()));
		this.bundle.putValue(key.toString(), value);
	}
	public void useFullyCustomDisplay() {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY, true);
	}
	public void setFullyCustomDisplayOfConfirm(ItemStack item) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_CONFIRM, item);
	}
	public void setFullyCustomDisplayOfVeto(ItemStack item) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_VETO, item);
	}
	public void setFullyCustomDisplayOfCancel(ItemStack item) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_CANCEL, item);
	}
	public void setFullyCustomDisplayOfCountdown(ItemStack item) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_COUNTDOWN, item);
	}
	public void setFullyCustomDisplayOfPrompt(ItemStack item) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_PROMPT, item);
	}
	
	public void useMaterialCustomDisplay() {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY, null);
	}
	public void setMaterialCustomDisplayOfConfirm(Material type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_CONFIRM, type);
	}
	public void setMaterialCustomDisplayOfVeto(Material type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_VETO, type);
	}
	public void setMaterialCustomDisplayOfCancel(Material type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_CANCEL, type);
	}
	public void setMaterialCustomDisplayOfCountdown(Material type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_COUNTDOWN, type);
	}
	public void setMaterialCustomDisplayOfPrompt(Material type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMDISPLAY_PROMPT, type);
	}
	
	public void useCustomGrid() {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID, EChooseMenuViewIntentKey.CUSTOMGRID);
	}
	public void setCustomGridOfViewType(EContainerType type) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_MENUTYPE, type);
	}
	public void setCustomGridOfConfirm(int slot) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_CONFIRM, slot);
	}
	public void setCustomGridOfVeto(int slot) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_VETO, slot);
	}
	public void setCustomGridOfCancel(int slot) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_CANCEL, slot);
	}
	public void setCustomGridOfCountdown(int slot) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_COUNTDOWN, slot);
	}
	public void setCustomGridOfPrompt(int slot) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOMGRID_PROMPT, slot);
	}
	public void setCustomTitle(String title) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOM_TITLE, title);
	}
	public void setChooseCountdown(int second) {
		if(second < 1 || second > 127) throw new RuntimeException("The original required a limit of 127. Technical requirements: Lower limit is 1"
				+ "(原版要求，上限为127。技术要求，下限为1)");
		this.putValue(EChooseMenuViewIntentKey.COUNTDOWN, second);
	}
	public void setCustomPromptName(String str) {
		if(str == null || str.isEmpty()) throw new RuntimeException("NULL and empty characters are not allowed in principle(原则上不允许NULL和空字符)");
		this.putValue(EChooseMenuViewIntentKey.CUSTOM_PROMPT_NAME, str);
	}
	public void setCustomPromptLore(List<String> lore) {
		this.putValue(EChooseMenuViewIntentKey.CUSTOM_PROMPT_LORE, lore);
	}
	public void setForwardContent(Object obj) {
		this.putValue(EChooseMenuViewIntentKey.FORWARD_CONTENT, obj);
	}
}